package com.keepsport.keepsportapi.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.keepsport.keepsportapi.dto.CommunityRemarkDto;
import com.keepsport.keepsportapi.entity.CommunityRemark;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/***
 *         O
 *      _ooOoo_
 *     o8888888o
 *     88" . "88
 *     (| -_- |)
 *      O\ = /O
 *  ____/`---'\____
 *  ...............
 *  佛祖保佑  永无BUG
 *   Data:2022/7/2
 *   Author:King
 *   Description:
 */
public interface CommunityRemarkDao extends BaseMapper<CommunityRemark> {
    //姑且不用
//    SELECT a.`name`,c.`content`,c.`ctime`,u.`name`,r.content, r.`ctime`
//    FROM t_community_remark r
//    INNER JOIN t_user u
//    ON u.`id`=r.`uid`
//    INNER JOIN t_community_circle c
//    ON r.`cid`=c.`id`
//    INNER JOIN t_user a
//    ON c.`uid`=a.`id`
    @Select("SELECT u.`name`,r.content, r.`ctime`\n" +
            "FROM t_community_remark r\n" +
            "INNER JOIN t_user u\n" +
            "ON u.`id`=r.`uid`\n" +
            "INNER JOIN t_community_circle c\n" +
            "ON r.`cid`=c.`id`\n" +
            "ORDER BY r.`ctime` DESC")
    List<CommunityRemarkDto> selectAll();
    @Select("select tu.id as tuid,tcr.cid as tcrid,tu.name,tcr.content,tcr.ctime from t_community_remark tcr inner join t_user tu on tu.id = tcr.uid  where cid = #{cid} order by tcr.ctime desc")
    List<CommunityRemarkDto> selectAllById(@Param("cid") int id);
}
